<template>
  <div class="content-body" :style="borderStyle">
    <div class="user-content">
      <div class="user-image">
        <el-image class="user-tx" :src="user.avatarName === null ? tx: baseURL.substring(0,baseURL.length -1) + user.avatarName" />
      </div>
      <div class="user-right">
        <div class="user-right-body">
          <div class="user-info">
            <div class="user-content-body">{{ entity[setting.firstColumn] }}</div>
            <div class="user-content-body"><div class="content-span">{{ entity[setting.secondColumn] }}</div></div>
          </div>
          <div v-if="setting.data" class="user-tj">
            <div v-for="(item,index) in setting.data" :key="'tj-'+index" class="user-content custom-padding">
              <visiting-slot :column="item" @fetch-data="callBack" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import VisitingSlot from './slot/visitingSlot';
import { mapGetters } from 'vuex';
import setImage from '@/assets/images/user.png';
import { queryAllSystemData } from '@/api/portal/manager/analysis';
export default {
  name: 'PcVisitingCardV1',
  components: { VisitingSlot },
  computed: {
    ...mapGetters([
      'user'
    ]),
    borderStyle() {
      if (this.temp.sfdzqp === true) {
        return { position: 'absolute', left: '0px', right: '0px', top: '0px', bottom: '0px' };
      }
      return { height: this.temp.defaultHeight };
    }
  },
  props: {
    temp: {
      type: Object,
      default() {
        return {};
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    layout: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      tx: setImage,
      baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
      loading: false,
      entity: {},
      setting: {},
      column: {},
      customStyle: {},
      titleStyle: {},
      bodyStyle: {}
    };
  },
  watch: {
    layout: {
      handler(newData, oldData) {
        this.customStyle = newData;
        this.titleStyle = { backgroundColor: newData.mrlb, opacity: newData.tmd };
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    temp: {
      handler(newData, oldData) {
        if (this.showHeader === true) {
          const pzx = JSON.parse(newData.data.pzx);
          this.setting = pzx;
          this.column = pzx.data;
          this.cid = newData.data.id;
          if (pzx.isRefresh !== undefined && pzx.isRefresh === true) {
            this.isRefresh = pzx.isRefresh;
          }
          if (pzx.refreshTime !== undefined && pzx.refreshTime !== null) {
            this.refreshTime = pzx.refreshTime;
          }
          this.initData();
        } else {
          const pzx = JSON.parse(newData.pzx);
          this.setting = pzx;
          if (pzx.isRefresh !== undefined && pzx.isRefresh === true) {
            this.isRefresh = pzx.isRefresh;
          }
          if (pzx.refreshTime !== undefined && pzx.refreshTime !== null) {
            this.refreshTime = pzx.refreshTime;
          }
          this.column = pzx.data;
          this.cid = newData.id;
          this.initData();
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    callBack(item) {
      if (undefined !== item) {
        item.menuId = this.temp.menu.id;
        item.menuName = this.temp.menu.name;
        item.showHeader = true;
        this.$emit('fetch-data', item);
      }
    },
    initData() {
      queryAllSystemData({ cid: this.cid }).then(res => {
        const { data } = res;
        if (undefined !== data.dataList && data.dataList !== null) {
          this.dataList = data.dataList;
          if (this.dataList.length > 0) {
            this.entity = this.dataList[0];
          }
        }
      }).catch(() => {
        this.dataList = [];
      });
    }
  }
};
</script>

<style scoped>
.content-body {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  overflow: hidden;
  background-color: #ffffff;
}
.user-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: row nowrap;
  position: relative;
}
.user-image {
  width: 75px;
  flex: 0 1 auto;
  height: 100%;
  position: relative;
  text-align: center;
}
.user-right {
  flex: 1 1 auto;
  height: 100%;
  display: flex;
  flex-flow: column nowrap;
  align-content: center;
  position: relative;
}
.user-right-body {
  width: 100%;
  height: 102px;
  top: 50%;
  margin-top: -51px;
  position: relative;
  display: flex;
  flex-flow: column nowrap;
}
.user-info {
  flex: 0 1 auto;
  width: 100%;
  height: 50%;
  display: flex;
  flex-flow: row nowrap;
  align-content: center;
  padding: 0px 10px;
  box-sizing: border-box;
}
.user-tx {
  width: 74px;
  height: 102px;
  top: 50%;
  margin-top: -51px;
  border-radius: 4px;
}
.user-tj {
  flex: 0 1 auto;
  width: 100%;
  height: 50%;
  display: flex;
  flex-flow: row nowrap;
  box-sizing: border-box;
}
.user-content {
  flex: 1 1 auto;
  text-align: center;
  cursor: pointer;
  padding: 5px 0px;
  box-sizing: border-box;
  position: relative;
}
.user-content-body {
  flex: 0 1 auto;
  text-align: left;
  align-content: center;
  font-size: 14px;
  padding: 18px 5px;
  box-sizing: border-box;
}
.custom-padding:not(:first-child)::before {
  content:'';
  position: absolute;
  background-color: #E4E7ED;
  width: 2px;
  top: 14px;
  bottom: 14px;
}
.content-span {
  font-size: 12px;
  line-height: 15px;
  background-color: #F2F6FC;
  border: 1px solid #E4E7ED;
  border-radius: 2px;
  padding: 0px 3px;
  color: #67C23A;
}
</style>
